package com.atguigu.lease.web.admin.custom.converter;

import com.atguigu.lease.model.enums.ItemType;
import org.springframework.core.convert.converter.Converter;
import org.springframework.stereotype.Component;

/**
 * 自定义String转换为枚举类的操作
 */
@Component
public class StringToItemTypeConverter implements Converter<String,ItemType> {

    @Override
    public ItemType convert(String s) {
        for (ItemType item : ItemType.values()) {
            if (item.getCode().equals(Integer.parseInt(s))) {
                return item;
            }
        }
        throw new RuntimeException("code:" + s + "code非法");
    }
}
